import { MICRO_SERVICE_ADMIN } from '~/constants/service-constant.ts'
import type { RoleReq, RoleResp } from '~/api/setting/model/dept.ts'
import type { RolePermissionReq } from '~/api/setting/model/role-permission.ts'
import type { Page, Query } from '~/api/base/base-model.ts'

enum Api {
  QueryRolePage = '/webservice/role/queryRolePage',
  CreateRole = '/webservice/role/createRole',
  ModifyRole = '/webservice/role/modifyRole',
  EnabledRoleStateById = '/webservice/role/enabledRoleStateById',
  RemoveRoleById = '/webservice/role/removeRoleById',
  BindRolePermissionRelation = '/webservice/role/bindRolePermissionRelation',
  UnBindRolePermissionRelation = '/webservice/role/unBindRolePermissionRelation',
}

/**
 * 获取角色树
 * @param params 角色实体
 */
export function queryRolePageApi(params?: Query<RoleReq>) {
  return usePost<Page<RoleResp>, RoleReq>(MICRO_SERVICE_ADMIN + Api.QueryRolePage, params)
}

/**
 * 创建角色
 * @param params 角色实体
 */
export function createRoleApi(params?: RoleReq) {
  return usePost<RoleResp, RoleReq>(MICRO_SERVICE_ADMIN + Api.CreateRole, params)
}

/**
 * 修改角色
 * @param params 角色实体
 */
export function modifyRoleApi(params?: RoleReq) {
  return usePost<RoleResp, RoleReq>(MICRO_SERVICE_ADMIN + Api.ModifyRole, params)
}

/**
 * 修改角色（启用/停用）状态
 * @param params 角色实体
 */
export function enabledRoleStateByIdApi(params?: RoleReq) {
  return useGet<RoleResp, RoleReq>(MICRO_SERVICE_ADMIN + Api.EnabledRoleStateById, params)
}

/**
 * 删除角色
 * @param params 角色实体，使用其中ID
 */
export function removeRoleByIdApi(params?: RoleReq) {
  return useGet<boolean>(MICRO_SERVICE_ADMIN + Api.RemoveRoleById, params)
}

/**
 * 绑定角色和权限关系
 * @param params 角色实体
 */
export function bindRolePermissionRelationApi(params?: RolePermissionReq) {
  return usePost<RoleResp, RoleReq>(MICRO_SERVICE_ADMIN + Api.BindRolePermissionRelation, params)
}

/**
 * 解除角色和权限关系
 * @param params 角色实体
 */
export function unBindRolePermissionRelationApi(params?: RolePermissionReq) {
  return usePost<RoleResp, RoleReq>(MICRO_SERVICE_ADMIN + Api.UnBindRolePermissionRelation, params)
}
